package com.ys.tdm.service.code.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.ys.tdm.bean.code.ServiceType;
import com.ys.tdm.dao.code.IServiceTypeDao;
import com.ys.tdm.service.code.IServiceTypeService;
import com.ys.tdm.util.StringTools;




/**
 * 数据库类型信息Service实现
 * @author hhj
 * @date 2018-03-07 10:23:27
 */
@Service
public class ServiceTypeServiceImpl implements IServiceTypeService {

	@Resource
	private IServiceTypeDao serviceTypeDao;

	@Override
	public ServiceType getServiceTypeById(String id) throws Exception {
		return StringUtils.isNotBlank(id) ? this.serviceTypeDao.getServiceTypeById(id.trim()) : null;
	}

	@Override
	public List<ServiceType> getServiceTypeByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		return StringUtils.isNotBlank(ids) ? this.serviceTypeDao.getServiceTypeByIds(ids) : null;
	}
	
	@Override
	public List<ServiceType> getServiceTypeByIdsList(List<String> ids) throws Exception {
		return CollectionUtils.isNotEmpty(ids) ? this.serviceTypeDao.getServiceTypeByIdsList(ids) : null;
	}

	@Override
	public List<ServiceType> getAll(ServiceType serviceType) throws Exception {
		return null != serviceType ? this.serviceTypeDao.getAll(serviceType) : null;
	}

	/*@Override
	public PagerModel<ServiceType> getPagerModelByQuery(ServiceType serviceType, Query query)
			throws Exception {
		return (null != serviceType && null != query) ? this.serviceTypeDao.getPagerModelByQuery(serviceType, query) : null;
	}*/
	
	@Override
	public int getByPageCount(ServiceType serviceType)throws Exception {
		return (null != serviceType) ? this.serviceTypeDao.getByPageCount(serviceType) : 0;
	}

	@Override
	public void insertServiceType(ServiceType serviceType) throws Exception {
		this.serviceTypeDao.insertServiceType(serviceType);
	}
	
	@Override
	public void insertServiceTypeBatch(List<ServiceType> serviceTypes) throws Exception {
		this.serviceTypeDao.insertServiceTypeBatch(serviceTypes);
	}
	
	@Override
	public void delServiceTypeById(String id) throws Exception {
		if (StringUtils.isNotBlank(id)) {
			this.serviceTypeDao.delServiceTypeById(id.trim());
		}
	}
	
	@Override
	public void delServiceTypeByIds(String ids) throws Exception {
		ids = StringTools.converString(ids);
		if(StringUtils.isNotBlank(ids)){
			this.serviceTypeDao.delServiceTypeByIds(ids);
		}
	}
	
	@Override
	public void delServiceTypeByIdsList(List<String> ids) throws Exception {
		if(CollectionUtils.isNotEmpty(ids)){
			this.serviceTypeDao.delServiceTypeByIdsList(ids);
		}
	}

	@Override
	public int updateServiceType(ServiceType serviceType) throws Exception {
		return this.serviceTypeDao.updateServiceType(serviceType);
	}
	
	@Override
	public int updateServiceTypeByIds(String ids,ServiceType serviceType) throws Exception {
		return this.serviceTypeDao.updateServiceTypeByIds(ids, serviceType);
	}
	
	@Override
	public int updateServiceTypeByIdsList(List<String> ids,ServiceType serviceType) throws Exception {
		return this.serviceTypeDao.updateServiceTypeByIdsList(ids, serviceType);
	}
	
	@Override
	public int updateServiceTypeList(List<ServiceType> serviceTypes) throws Exception {
		return this.serviceTypeDao.updateServiceTypeList(serviceTypes);
	}
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成"'1','2','3','4'..."这种形式
	 * @param strs
	 * @return
	 
	private String converString(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				StringBuffer sbf = new StringBuffer("");
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						sbf.append("'").append(str.trim()).append("'").append(",");
					}
				}
				if (sbf.length() > 0) {
					sbf = sbf.deleteCharAt(sbf.length() - 1);
					return sbf.toString();
				}
			}
		}
		return "";
	}*/
	
	/***
	 * 将"1,2,3,4,5..."这种形式的字符串转成List<String> 集合
	 * 
	 * @param strs
	 * @return
	 
	private List<String> converStringToList(String strs) {
		if (StringUtils.isNotBlank(strs)) {
			String[] idStrs = strs.trim().split(",");
			if (null != idStrs && idStrs.length > 0) {
				List<String> strsList = new ArrayList<String>();
				for (String str : idStrs) {
					if (StringUtils.isNotBlank(str)) {
						strsList.add(str.trim());
					}
				}
				if (strsList.size() > 0) {
					return strsList;
				}
			}
		}
		return null;
	}
	*/
	
	//------------api------------
	
}

